/**
 * Maven Helper Extension - Simplified Build
 * 
 * This script packages the extension without going through the full TypeScript compilation
 */

const fs = require('fs');
const path = require('path');
const { exec } = require('child_process');

// Extension paths
const extensionDir = __dirname;
const srcDir = path.join(extensionDir, 'src');
const outDir = path.join(extensionDir, 'dist');

// Create output directory if it doesn't exist
if (!fs.existsSync(outDir)) {
    fs.mkdirSync(outDir, { recursive: true });
}

// 1. Copy all JS files from src to dist
console.log('Copying JS files...');
try {
    const jsFiles = fs.readdirSync(srcDir).filter(file => file.endsWith('.js'));
    jsFiles.forEach(file => {
        const srcPath = path.join(srcDir, file);
        const destPath = path.join(outDir, file);
        fs.copyFileSync(srcPath, destPath);
        console.log(`Copied ${file}`);
    });
} catch (err) {
    console.error('Error copying JS files:', err);
}

// 2. Package extension
console.log('\nPackaging extension...');
exec('npx vsce package --no-dependencies', { cwd: extensionDir }, (error, stdout, stderr) => {
    if (error) {
        console.error(`Error packaging extension: ${error.message}`);
        return;
    }
    
    if (stderr) {
        console.error(`Packaging stderr: ${stderr}`);
    }
    
    console.log(stdout);
    console.log('\nExtension packaged successfully!');
});
